package com.yanxp.mybatis.dao.impl;

import com.yanxp.mybatis.dao.CountryDao;
import com.yanxp.mybatis.entity.Country;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class CountryDaoImpl implements CountryDao {
    @Override
    public List<Country> findAll() throws IOException {
        InputStream resourceAsStream =
                Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new
                SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        List<Country> userList = sqlSession.selectList("test.selectAll");
        sqlSession.close();
        return userList;
    }
}
